const path = require('path');
const htmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  // 模式：development or production
  mode: 'development',

  // 快速定位 error or warning
  devtool: 'source-map',

  // 开发：本地服务器
  devServer: {
    watchOptions: {
      ignored: /node_modules/
    },
    open: true,
    port: 3000
  },

  // 入口
  entry: {
    index: './src/index.js',
  },

  resolve: {
    // 扩展名可省略
    extensions: ['.js', '.css', '.less']
  },

  // 模块
  module: {
    rules: [
      {
        // css 样式文件
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
      },
      {
        // less 样式文件
        test: /\.less$/,
        use: [
          'style-loader',
          'css-loader',
          'less-loader'
        ]
      },
      {
        // 文件处理
        test: /\.(png|jpg|jpeg|gif|ico|woff|eot|svg|ttf|jfif)$/i,
        loaders: 'url-loader?limit=1024&name=img/[name]-[hash:16].[ext]'
      }
    ]
  },

  // 插件扩展
  plugins: [
    new htmlWebpackPlugin({
      filename: 'index.html',
      template: './index.html',
      title: '仿腾讯课堂课程模块哈'
    }),
  ],

  // 出口文件及目录配置
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'js/[name].js'
  }
}